package com.example.springboot.modules.mybatis.controller;

import com.example.springboot.common.annotation.SysLog;
import com.example.springboot.globalutils.BizException;
import com.example.springboot.globalutils.Paged;
import com.example.springboot.globalutils.R;
import com.example.springboot.modules.mybatis.controller.req.AccountsPageReq;
import com.example.springboot.modules.mybatis.entity.AccountsEntity;
import com.example.springboot.modules.mybatis.service.AccountsService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mybatis")
public class MybatisController {

    @Autowired
    private AccountsService accountsService;


    @GetMapping("/user")
    public R<Integer> getUser(){
        AccountsEntity byId = accountsService.getById(1);
        System.out.println(byId);
//        int a = 0/0;
        throw new BizException(500,"出异常了。。。。");
    }

    @SysLog("我是系统日志注解")
    @PostMapping("/user/page")
    public R<Paged<AccountsEntity>> getUserList(@RequestBody AccountsPageReq req){
        Paged<AccountsEntity> page =  accountsService.getUserList(req);
        return R.success(page);
    }
}
